/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sh.ndt.common.service;

import com.sh.ndt.common.entity.EmailContent;
import com.sh.ndt.exam.service.ExamServiceImpl;
import com.sh.ndt.exception.ServiceException;
import org.apache.log4j.Logger;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

/**
 *
 * @author Prashanth
 */
public class EmailServiceImpl implements EmailService {

    private MailSender mailSender;
    private static final Logger LOGGER = Logger.getLogger(ExamServiceImpl.class);

    public EmailServiceImpl(MailSender mailSender) {
        this.setMailSender(mailSender);
        LOGGER.debug("************ Instantianted EmailServiceImpl Bean ************");
    }

    @Override
    public String prepareEmailContent() throws ServiceException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean sendEmail(EmailContent emailContent) throws ServiceException {
        LOGGER.debug("************ Instantianted sendEmail Bean ************");
        SimpleMailMessage message = new SimpleMailMessage();

        message.setFrom(emailContent.getFrom());
        message.setTo(emailContent.getTo());
        message.setSubject(emailContent.getSubject());
        message.setText(emailContent.getMessage());

        getMailSender().send(message);

        LOGGER.debug("************ Email has been sent from server ************");
        return true;
    }

    /**
     * @return the mailSender
     */
    public MailSender getMailSender() {
        return mailSender;
    }

    /**
     * @param mailSender the mailSender to set
     */
    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }

}
